﻿//////////////////////////////////////////////////////////////////////////////
//This file is part of My Nes                                               //
//A Nintendo Entertainment System Emulator.                                 //
//                                                                          //
//Copyright © 2009 Ala Hadid (AHD)                                          //
//                                                                          //
//My Nes is free software; you can redistribute it and/or modify            //
//it under the terms of the GNU General Public License as published by      //
//the Free Software Foundation; either version 2 of the License, or         //
//(at your option) any later version.                                       //
//                                                                          //
//My Nes is distributed in the hope that it will be useful,                 //
//but WITHOUT ANY WARRANTY; without even the implied warranty of            //
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
//GNU General Public License for more details.                              //
//                                                                          //
//You should have received a copy of the GNU General Public License         //
//along with this program; if not, write to the Free Software               //
//Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA//
//////////////////////////////////////////////////////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AHD.MyNes.Nes
{
    public class Joypad
    {
        // Fields
        public  bool A;
        public  bool B;
        public  bool Down;
        public  bool Left;
        public  bool Right;
        public  bool Select;
        public  bool Start;
        public  bool Up;

        public  bool P2_A;
        public  bool P2_B;
        public  bool P2_Down;
        public  bool P2_Left;
        public  bool P2_Right;
        public  bool P2_Select;
        public  bool P2_Start;
        public  bool P2_Up;
        // Methods
        public  int GetJoyData1()
        {
            int num = 0;
            if (A)
            {
                num |= 1;
            }
            if (B)
            {
                num |= 2;
            }
            if (Select)
            {
                num |= 4;
            }
            if (Start)
            {
                num |= 8;
            }
            if (Up)
            {
                num |= 0x10;
            }
            if (Down)
            {
                num |= 0x20;
            }
            if (Left)
            {
                num |= 0x40;
            }
            if (Right)
            {
                num |= 0x80;
            }
            return num;
        }
        public  int GetJoyData2()
        {
            int num = 0;
            if (P2_A)
            {
                num |= 1;
            }
            if (P2_B)
            {
                num |= 2;
            }
            if (P2_Select)
            {
                num |= 4;
            }
            if (P2_Start)
            {
                num |= 8;
            }
            if (P2_Up)
            {
                num |= 0x10;
            }
            if (P2_Down)
            {
                num |= 0x20;
            }
            if (P2_Left)
            {
                num |= 0x40;
            }
            if (P2_Right)
            {
                num |= 0x80;
            }
            return num;
        }
    }
}
